unit PacocFileManipulation;

interface

function  OpenFileHandle(Path: String{; shared: boolean}): Integer;
procedure CloseFileHandle(FileNum: Integer);

var
  OpenFiles: packed array of record
    F: File;
    IsFree: Boolean;
  end;

implementation

uses SysUtils;

function OpenFileHandle(Path: String{; shared: boolean}): Integer;
var
  I: Integer;
begin
  Result:= -1;
  for I:= 0 to High(OpenFiles) do
    if(OpenFiles[I].IsFree)then
    begin
      try
        AssignFile(OpenFiles[I].F, Path);
        Result:= I;
        OpenFiles[I].IsFree:= False;
      except
        exit;
      end;
      exit;
    end;
  SetLength(OpenFiles, I + 1);
  try
    AssignFile(OpenFiles[I].F, Path);
    OpenFiles[I].IsFree:= False;
    Result:= I;
  except
    SetLength(OpenFiles, I);
  end;
end;

procedure CloseFileHandle(FileNum: Integer);
begin
  try
    CloseFile(OpenFiles[FileNum].F);
    OpenFiles[FileNum].IsFree:= True;
  except
  end;
end;

end.
